﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace octopus_project.enumeration {

    public enum WarPhaseSprite : byte {
        PLAYER_CURSOR = 0
        ///EMPIEZAN EN EL 40 LOS GENERICOS
    }

    public static class WarPhaseSpriteExtensions {

        static public Texture2D SpriteImage;

        public static WarPhaseSprite getFromValue (byte tileTypeValue) {
            string name = Enum.GetName(typeof(WarPhaseSprite), tileTypeValue);
            return (WarPhaseSprite)Enum.Parse(typeof(WarPhaseSprite), name);
        }

        static public Rectangle GetSourceRectangle (this WarPhaseSprite tileType, PlayersColor playersColor = PlayersColor.UNDEFINED) {
            int tileY = (byte)tileType / (SpriteImage.Width / Constant.TILE_IMAG_SIDE);
            int tileX = (byte)tileType % (SpriteImage.Width / Constant.TILE_IMAG_SIDE);

            if (playersColor != PlayersColor.UNDEFINED) {

                int realType = (byte)tileType + (byte)playersColor * (byte)(SpriteImage.Width / Constant.TILE_IMAG_SIDE);
                tileY = (byte)realType / (SpriteImage.Width / Constant.TILE_IMAG_SIDE);
                tileX = (byte)realType % (SpriteImage.Width / Constant.TILE_IMAG_SIDE);

            }
            else {

                tileY = (byte)tileType / (SpriteImage.Width / Constant.TILE_IMAG_SIDE);
                tileX = (byte)tileType % (SpriteImage.Width / Constant.TILE_IMAG_SIDE);
            }
            return new Rectangle(tileX * Constant.TILE_IMAG_SIDE, tileY * Constant.TILE_IMAG_SIDE, Constant.TILE_IMAG_SIDE, Constant.TILE_IMAG_SIDE);
        }
    }
}
